package io.xccit.aischool.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.xccit.aischool.entity.Clazz;
import io.xccit.aischool.mapper.IClazzMapper;
import io.xccit.aischool.service.IClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author CH_ywx
 * @date 2023-06-06
 * @description
 */
@Service("clazzService")
@Transactional
public class ClazzServiceImpl extends ServiceImpl<IClazzMapper, Clazz> implements IClazzService {

    @Autowired
    private IClazzMapper clazzMapper;
    @Override
    public Page<Clazz> getClazzByOpr(Page<Clazz> clazzPage, String clazzName,String gradeName) {
        QueryWrapper<Clazz> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(clazzName)){
            wrapper.like("name",clazzName);
        }
        if(!StringUtils.isEmpty(gradeName)){
            wrapper.eq("grade_name",gradeName);
        }
        return clazzMapper.selectPage(clazzPage,wrapper);
    }

    @Override
    public List<Clazz> getAllClazz() {
        QueryWrapper<Clazz> wrapper = new QueryWrapper<>();
        return clazzMapper.selectList(wrapper);
    }
}
